<script setup>
import {
    Management,
    Promotion,
    UserFilled,
    User,
    EditPen,
    SwitchButton,
    CaretBottom,
    Setting,
} from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'

const router = useRouter()

import avatar from '@/assets/profile.jpg'

import { useRouter } from 'vue-router'

import { getUserInfo, userlogoutService } from '@/api/user.js';

import { ref } from 'vue'



const logout = async () => {
    let loginresult = await getUserInfo();
    //console.log(loginresult.userAccount)
    let resultData = await userlogoutService(loginresult.adminAccount)
    //console.log(resultData)
    ElMessage.success(resultData.msg ? resultData.msg : '注销成功');
    //跳转到首页， 使用路由来完成跳转
    router.push('/user')
}
const reset = async () => {
    alert("密码重置成功，默认密码为：123456")
}

const username = ref()
const getname = async () => {
    let result = await getUserInfo()
    username.value = result.adminAccount;

}
getname();


</script>

<template>
    <el-container class="layout-container">
        <!-- 左侧菜单 -->
        <el-aside width="200px">
            <p style="font-weight: bold; text-align: center;font-size: 18px; margin-top: 40px">在线医疗管理系统</p>
            <div class="el-aside__logo"></div>
            <el-menu active-text-color="#ffd04b" background-color="#ff9300" text-color="#fff" router>
                <el-menu-item index="/user/userinfo">
                    <el-icon>
                        <User />
                    </el-icon>
                    <span>用户管理</span>
                </el-menu-item>
                <el-menu-item index="/user/registration">
                    <el-icon>
                        <Management />
                    </el-icon>
                    <span>就医中心</span>
                </el-menu-item>

                <el-menu-item index="/user/prescription">
                    <el-icon>
                        <Promotion />
                    </el-icon>
                    <span>诚信档案管理</span>
                </el-menu-item>
                <el-menu-item index="/user/inspection">
                    <el-icon>
                        <EditPen />
                    </el-icon>
                    <span>意见反馈</span>
                </el-menu-item>
                <el-menu-item index="/user/setting">
                    <el-icon>
                        <Setting/>
                    </el-icon>
                    <span>系统设置维护</span>
                </el-menu-item>
                <el-sub-menu>
                    <template #title>
                        <el-icon>
                            <UserFilled />
                        </el-icon>
                        <span>个人中心</span>
                    </template>
                    <el-menu-item @click="reset">
                        <el-icon>
                            <EditPen />
                        </el-icon>
                        <span>重置密码</span>
                    </el-menu-item>
                    <el-menu-item>
                        <el-icon>
                            <User />
                        </el-icon>
                        <router-link to="/user">
                            <span class="gr">退出登录</span>
                        </router-link>
                    </el-menu-item>
                    <el-menu-item @click="logout">
                        <el-icon>
                            <SwitchButton />
                        </el-icon>
                        <span>账户注销</span>
                    </el-menu-item>
                </el-sub-menu>
            </el-menu>
        </el-aside>
        <!-- 右侧主区域 -->
        <el-container>
            <!-- 头部区域 -->
            <el-header>
                <div>用户：<strong>{{ username }}</strong></div>
                <el-dropdown placement="bottom-end">
                    <span class="el-dropdown__box">

                        <el-avatar :src="avatar" />
                    </span>
                    <!-- <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item command="profile" :icon="User">基本资料</el-dropdown-item>
                            <el-dropdown-item command="avatar" :icon="SwitchButton">账户注销</el-dropdown-item>
                            <el-dropdown-item command="password" :icon="EditPen">重置密码</el-dropdown-item>
                            <el-dropdown-item command="quit" :icon="User">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </template> -->
                </el-dropdown>
            </el-header>
            <!-- 中间区域 -->
            <el-main>
                <router-view>

                </router-view>
            </el-main>
            <!-- 底部区域 -->
            <el-footer>
                医疗服务 ©2024
            </el-footer>
        </el-container>
    </el-container>
</template>

<style lang="scss" scoped>
.layout-container {
    height: 100vh;

    .el-aside {
        background-color: #ff9300;

        &__logo {
            height: 120px;
            // background: url('@/assets/logo.png') no-repeat center / 120px auto;
        }

        .el-menu {
            border-right: none;
        }

        .gr {
            color: #fffdfd;
        }
    }

    .el-header {
        background-color: #fffdfd;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .el-dropdown__box {
            display: flex;
            align-items: center;

            .el-icon {
                color: #999;
                margin-left: 10px;
            }

            &:active,
            &:focus {
                outline: none;
            }
        }
    }

    .el-footer {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        color: #666;
    }


}
</style>